//测试配置结果
/*
document.querySelector('#btn-register').addEventListener('click',()=>{
    axios({
        url:'/register',
        method:'post',
        data:{
            username:'wuhan002',
            password:'123456'
        }
    })
})
    */

//用户注册功能
//1.收集并检验数据
//2.提交数据
document.querySelector('#btn-register').addEventListener('click',()=>{
 const form =document.querySelector('.register-form')
 const data =serialize(form,{empty:true,hash:true})
 const  { username,password}=data
 //非空判断
 if(username ==='' || password ===''){
    showToast('用户名或密码不能为空')
    return
 }
 //长度校验
 if(username.length< 8||username.length>15 || password.length<6 ||password.length>15){
    showToast('用户名长度8-15,密码长度6-15')
    return
 }
 //数据提交
 try{
    const res= await axios.post('/register',{username,password})
    showToast(res.data.message)
 }catch(error){
    showToast(error.response.data.message)
 }
})